package setting

import (
	"context"
	"strings"

	"mall/common/resultx"
	"mall/service/forum/api/internal/svc"
	"mall/service/forum/api/internal/types"
	"mall/service/forum/rpc/forumclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetPageSettingLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetPageSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPageSettingLogic {
	return &GetPageSettingLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPageSettingLogic) GetPageSetting(req *types.PageSettingReq) (resp *types.BaseDataInfo, err error) {
	if req.Key == nil || len(strings.TrimSpace(*req.Key)) == 0 {
		return nil, resultx.NewErrCode(resultx.REUQEST_PARAM_ERROR)
	}

	res, err := l.svcCtx.ForumRpc.BackendGetPageSetting(l.ctx, &forumclient.BackendGetPageSettingReq{
		Key: req.Key,
	})
	if err != nil {
		return nil, err
	}

	return &types.BaseDataInfo{
		Status:  "ok",
		Message: "",
		Data:    res.Msg,
	}, nil
}
